from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
import json
import os

from .routers import note, provider, model, config

def custom_openapi():
    with open("app/openapi.json", "r", encoding="utf-8") as f:
        return json.load(f)

def create_app(lifespan) -> FastAPI:
    app = FastAPI(title="BiliNote", lifespan=lifespan)
    app.include_router(note.router, prefix="/api")
    app.include_router(provider.router, prefix="/api")
    app.include_router(model.router, prefix="/api")
    app.include_router(config.router, prefix="/api")
    
    # 使用自定义的 OpenAPI 文档
    app.openapi = custom_openapi

    return app
